package ch03;

public class Crop {
private String name;                        // 名称
    private int growTime;                   // 成长期
    private int harvestTime;                // 采摘期
    private int numsOfFruits;               // 果实数量
    private String status;                  // 生长状态
    private boolean isHarvested;            // 是否采摘

    public Crop() {
    }

    public Crop(String name, int growTime, int harvestTime, int numsOfFruits) {
        this.name = name;
        this.growTime = growTime;
        this.harvestTime = harvestTime;
        this.numsOfFruits = numsOfFruits;
    }

    public Crop(String name, int growTime, int harvestTime, int numsOfFruits, String status, boolean isHarvested) {
        this.name = name;
        this.growTime = growTime;
        this.harvestTime = harvestTime;
        this.numsOfFruits = numsOfFruits;
        this.status = status;
        this.isHarvested = isHarvested;
    }

    public static Crop getCrop(int type){
        Crop crop = null;
        switch (type){
            case 1: crop = new AppleTree();break;
            case 2: crop = new Corn();break;
            case 3: crop = new Pear();break;
            default: System.out.println("您的输入有误！");break;
        }
        return crop;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getGrowTime() {
        return growTime;
    }

    public void setGrowTime(int growTime) {
        this.growTime = growTime;
    }

    public int getHarvestTime() {
        return harvestTime;
    }

    public void setHarvestTime(int harvestTime) {
        this.harvestTime = harvestTime;
    }

    public int getNumsOfFruits() {
        return numsOfFruits;
    }

    public void setNumsOfFruits(int numsOfFruits) {
        this.numsOfFruits = numsOfFruits;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public boolean isHarvested() {
        return isHarvested;
    }

    public void setHarvested(boolean harvested) {
        isHarvested = harvested;
    }

    /**
     * 输出作物特性
     */
    public void print(){
        System.out.println("******作物特性******");
        System.out.println("您种植了"+ this.getName() +"。");
        System.out.println("成长期"+ this.getGrowTime() +"天，"
                +"采摘期"+ this.getHarvestTime() +"天，"
                +"果实数量为"+ this.getNumsOfFruits() +"，现在处于"+ this.getStatus() +"。");
    }

    /**
     * 生长报告
     * @param day 生长的天数
     */
    public void printGrowReport(int day){
        if (day< this.getGrowTime()){
            this.setStatus("成长期");
            System.out.println("******"+ this.getName() +"生长报告（"+ this.getStatus() +"）******");
            System.out.println(this.getName() +"处于"+ this.getStatus());
            System.out.println("已生长"+day+"天，距离收获果实还有"+(this.getGrowTime() -day)+"天。");
        }else if(day< this.getGrowTime() + this.getHarvestTime()){
            this.setStatus("采摘期");
            System.out.println("******"+ this.getName() +"生长报告（"+ this.getStatus() +"）******");
            System.out.println(this.getName() +"处于"+ this.getStatus());
            if (!this.isHarvested()){
                System.out.println("果实已成熟，请尽快采摘！");
            }else{
                System.out.println("果实已成熟并已采摘完毕！");
            }
        }else{
            this.setStatus("已死亡");
            System.out.println("******"+ this.getName() +"生长报告（"+ this.getStatus() +"）******");
            System.out.println(this.getName() + this.getStatus() +"，请尽快清理土地！");
        }
    }

    /**
     * 采摘
     */
    public void harvest(){
        System.out.println("******"+ this.getName() +"收获果实（"+ this.getStatus() +"）******");
        if (this.getStatus() == "采摘期"){
            if (!this.isHarvested()){
                System.out.println("收获果实"+ this.getNumsOfFruits() +"个！");
                this.setHarvested(true);
            }else{
                System.out.println("果实已采摘！");
            }
        }else{
            System.out.println("抱歉！目前没有果实可以采摘！");
        }
    }
}
